<?php
/**
* Copyright 2009 Waag Society <http://www.waag.org>
* This file is part of Annotrax.
*
* Annotrax is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Annotrax is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Annotrax.
* If not, see http://www.gnu.org/licenses/gpl.html
*/

class Admin_Form_Setting_TopMovies extends Zend_Form{
	public function __construct( Default_Model_Setting $setting, $options = null ){
		parent::__construct( $options );

		$movie = new Default_Model_Movie();
		$movies = $movie->fetchAll();
		$values = unserialize( $setting->value );

		$options = array();

		foreach( $movies as $movie ){
			$options[$movie->id] = $movie->title;
		}

		$this->addElement('select', 'new_movie', array(
			'multiOptions'	=> $options
		));

		$this->addElement( 'submit', 'add', array('label' => 'Add new'));

		if( $values ){
			$movies = new Zend_Form_SubForm();
			foreach( $values as $priority => $value ){
				$form = new Zend_Form_SubForm();

				$form->addElement( 'text', 'priority', array(
					'label'	=> $value['title'],
					'value'	=> $priority
				));


				$movies->addSubForm( $form, $value['id'] );
			}

			$this->addSubForm( $movies, 'movies' );

		}

	}

	private function getFormRow( $value ){

		//$domain   = new Default_Model_Domain();
		//$form 	  = new Zend_Form_SubForm();
		//$keywords = array();
		//$domains  = array();
		//
		//$form->setLegend('Top movies');
		//
		//foreach( $this->_channel->getKeywords() as $keyword ){
		//	$keywords[$keyword->id] = $keyword->name;
		//}
		//foreach( $domain->fetchAll() as $domain ){
		//	$domains[$domain->id] = $domain->name;
		//}
		//
		//$form->addElement('text', 'keyword_name', array('label'	=> 'New keyword'));
		//$form->addElement('select', 'keyword_domain', array(
		//	'multiOptions'	=> $domains
		//));
		//
		//$form->addElement('MultiCheckbox', 'selected', array(
		//	'multiOptions'	=> $keywords,
		//));
		//
		//foreach( array( 'keyword_name', 'keyword_domain' ) as $name ){
		//	$element = $form->getElement($name);
		//	$element->removeDecorator('Label');
		//	$element->removeDecorator('HtmlTag');
		//}
		//
		//$element = $form->getElement( 'selected' );
		//$element->getDecorator('HtmlTag')->setOption('tag', 'div');
		//$element->removeDecorator('Label');
		//
		//$form->removeDecorator('HtmlTag');
		//
		//$form->addElement( 'submit', 'update', array(
		//	'label'	=> 'Update labels'
		//));
		//
		return $form;
	}
}
